package com.example.wechat.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.enums.BusinessType;
import com.example.project.utils.poi.ExcelUtil;
import com.example.wechat.model.WechatConversationMember;
import com.example.wechat.service.WechatConversationMemberService;

/**
 * 会话成员关系Controller
 * 
 * @author ruoyi
 * @date 2025-11-12
 */
@Controller
@RequestMapping("/wechat/members")
public class WechatConversationMemberController extends BaseController {

	private String prefix = "wechat/members";

	@Autowired
	private WechatConversationMemberService wechatConversationMemberService;

	@RequiresPermissions("wechat:members:view")
	@GetMapping()
	public String members() {
		return prefix + "/members";
	}

	/**
	 * 查询会话成员关系列表
	 */
	@RequiresPermissions("wechat:members:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WechatConversationMember wechatConversationMember) {
		startPage();
		List<WechatConversationMember> list = wechatConversationMemberService
				.selectWechatConversationMemberList(wechatConversationMember);
		return getDataTable(list);
	}

	/**
	 * 导出会话成员关系列表
	 */
	@RequiresPermissions("wechat:members:export")
	@Log(title = "会话成员关系", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(WechatConversationMember wechatConversationMember) {
		List<WechatConversationMember> list = wechatConversationMemberService
				.selectWechatConversationMemberList(wechatConversationMember);
		ExcelUtil<WechatConversationMember> util = new ExcelUtil<WechatConversationMember>(
				WechatConversationMember.class);
		return util.exportExcel(list, "会话成员关系数据");
	}

	/**
	 * 新增会话成员关系
	 */
	@RequiresPermissions("wechat:members:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存会话成员关系
	 */
	@RequiresPermissions("wechat:members:add")
	@Log(title = "会话成员关系", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WechatConversationMember wechatConversationMember) {
		return toAjax(wechatConversationMemberService.insertWechatConversationMember(wechatConversationMember));
	}

	/**
	 * 修改会话成员关系
	 */
	@RequiresPermissions("wechat:members:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		WechatConversationMember wechatConversationMember = wechatConversationMemberService
				.selectWechatConversationMemberById(id);
		mmap.put("wechatConversationMember", wechatConversationMember);
		return prefix + "/edit";
	}

	/**
	 * 修改保存会话成员关系
	 */
	@RequiresPermissions("wechat:members:edit")
	@Log(title = "会话成员关系", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WechatConversationMember wechatConversationMember) {
		return toAjax(wechatConversationMemberService.updateWechatConversationMember(wechatConversationMember));
	}

	/**
	 * 删除会话成员关系
	 */
	@RequiresPermissions("wechat:members:remove")
	@Log(title = "会话成员关系", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(wechatConversationMemberService.deleteWechatConversationMemberByIds(ids));
	}
}
